package com.example.study.controller;

import com.example.study.domain.User;
import com.example.study.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by gl on 2017/3/2.
 */
@Controller
public class UserController {

    private static final String PATH ="login/";

    @Autowired
    private UserService userService;

    @RequestMapping("/user/regist")
    @ResponseBody
    public String regist(User user){
        userService.save(user);
        return "1";
    }

    /**
     * 跳转到登录页面
     * @return
     */
    @RequestMapping(value = "/user/jump")
    public String pageJump(){
        return PATH+"login";
    }

    /**
     * 验证登录信息
     */
    @RequestMapping(value = "/user/login")
    public String login(User user){

            User u=userService.findByName(user.getName());
            if (u!=null){
                System.out.printf("登录成功");
                //return "index";
                return "mainPage";
            } else {
                System.out.printf("数据不存在");
                return "error";
            }
    }
}
